package com.inspur.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.inspur.system.dto.PmTaskDTO;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.inspur.common.annotation.Log;
import com.inspur.common.core.controller.BaseController;
import com.inspur.common.core.domain.AjaxResult;
import com.inspur.common.enums.BusinessType;
import com.inspur.system.domain.PmTask;
import com.inspur.system.service.IPmTaskService;
import com.inspur.common.utils.poi.ExcelUtil;
import com.inspur.common.core.page.TableDataInfo;

/**
 * 任务Controller
 * 
 * @author ruoyi
 * @date 2024-04-08
 */
@RestController
@RequestMapping("/system/task")
public class PmTaskController extends BaseController
{
    @Autowired
    private IPmTaskService pmTaskService;

    /**
     * 查询任务列表
     */
    @PreAuthorize("@ss.hasPermi('system:task:list')")
    @GetMapping("/list")
    public TableDataInfo list(PmTaskDTO pmTask)
    {
        startPage();
        List<PmTaskDTO> list = pmTaskService.selectPmTaskDTOList(pmTask);
        return getDataTable(list);
    }

    /**
     * 查询任务数量
     */
    @PreAuthorize("@ss.hasPermi('system:task:listnum')")
    @GetMapping("/listNum")
    public AjaxResult listNum()
    {
        return success(pmTaskService.selectPmTaskNum());
    }

    /**
     * 导出任务列表
     */
    @PreAuthorize("@ss.hasPermi('system:task:export')")
    @Log(title = "任务", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PmTask pmTask)
    {
        List<PmTask> list = pmTaskService.selectPmTaskList(pmTask);
        ExcelUtil<PmTask> util = new ExcelUtil<PmTask>(PmTask.class);
        util.exportExcel(response, list, "任务数据");
    }

    /**
     * 获取任务详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:task:query')")
    @GetMapping(value = "/{cTaskNo}")
    public AjaxResult getInfo(@PathVariable("cTaskNo") String cTaskNo)
    {
        return success(pmTaskService.selectPmTaskByCTaskNo(cTaskNo));
    }

    /**
     * 新增任务
     */
    @PreAuthorize("@ss.hasPermi('system:task:add')")
    @Log(title = "任务", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PmTask pmTask)
    {
        return toAjax(pmTaskService.insertPmTask(pmTask));
    }

    /**
     * 修改任务
     */
    @PreAuthorize("@ss.hasPermi('system:task:edit')")
    @Log(title = "任务", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PmTask pmTask)
    {
        return toAjax(pmTaskService.updatePmTask(pmTask));
    }

    /**
     * 删除任务
     */
    @PreAuthorize("@ss.hasPermi('system:task:remove')")
    @Log(title = "任务", businessType = BusinessType.DELETE)
	@DeleteMapping("/{cTaskNos}")
    public AjaxResult remove(@PathVariable String[] cTaskNos)
    {
        return toAjax(pmTaskService.deletePmTaskByCTaskNos(cTaskNos));
    }
}
